package com.app.coffeephilosophy.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;

import com.app.coffeephilosophy.R;
import com.app.coffeephilosophy.adapter.FreshAdapter;
import com.app.coffeephilosophy.adapter.SadAdapter;
import com.app.coffeephilosophy.adapter.WarmAdapter;


public class CoffeeMainActivity extends Activity {
	GridView gvFresh,gvWarm,gvSad;
	RadioButton rbFresh, rbWarm, rbSad;
	RelativeLayout rlFresh, rlWarm, rlSad;
	FreshAdapter gvAdapterFresh;
	WarmAdapter gvAdapterWarm;
	SadAdapter gvAdapterSad;
	
	private int[] imagesFresh=new int[]{R.drawable.kabuqinuo,R.drawable.lanshan,R.drawable.moka,
            R.drawable.kabuqinuo,R.drawable.lanshan,R.drawable.moka,
            R.drawable.kabuqinuo,R.drawable.moka};
	private int[] imagesWarm=new int[]{R.drawable.naifen,R.drawable.naixi,R.drawable.nailao,
			R.drawable.naihua,R.drawable.naicream,R.drawable.naicai,
			R.drawable.naiyou,R.drawable.naiqing};
	private int[] imagesSad=new int[]{R.drawable.at,R.drawable.chocolate,R.drawable.circle,R.drawable.youyu,
			R.drawable.yu,R.drawable.huangyun,R.drawable.hole,R.drawable.gao};

	private String[] textfresh=new String[]{"蓝山","摩卡","卡其诺","奶甜","蓝山","摩卡","卡其诺","小菲"};
	private String[] textwarm=new String[]{"奶芬","奶昔","奶酪","奶花","奶提","奶彩","奶冰","奶清"};
	private String[] textsad=new String[]{"怀旧","回味","咔琪","苦香","咔洞","摩卡","卡其诺","苦提"};
  
	/*
	private String[] textfresh= (String [])this.getResources().getStringArray(R.array.text_fresh);
	private String[] textwarm= (String [])this.getResources().getStringArray(R.array.text_warm);
	private String[] textsad= (String [])this.getResources().getStringArray(R.array.text_sad);
*/	    
	 
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.coffeemain);
		findViewById();
		setListener();
		setData();
		setItemListener();
//		rbFresh.performClick();
	}

	private void findViewById() {
		gvFresh = (GridView) findViewById(R.id.GridView01);
		gvWarm = (GridView) findViewById(R.id.GridView02);
		gvSad = (GridView) findViewById(R.id.GridView03);		
		rbFresh = (RadioButton) findViewById(R.id.RadioButton01);
		rbWarm = (RadioButton) findViewById(R.id.RadioButton02);
		rbSad = (RadioButton) findViewById(R.id.RadioButton03);
		rlFresh = (RelativeLayout) findViewById(R.id.RLFresh);
		rlWarm = (RelativeLayout) findViewById(R.id.RLWarm);
		rlSad = (RelativeLayout) findViewById(R.id.RLSad);
	}

	private void setListener() {
		rbFresh.setOnClickListener(new View.OnClickListener() {

			 
			public void onClick(View v) {
				rlFresh.setVisibility(View.VISIBLE);
				rlSad.setVisibility(View.GONE);
				rlWarm.setVisibility(View.GONE);
			}
		});
		rbSad.setOnClickListener(new View.OnClickListener() {

			 
			public void onClick(View v) {
				rlFresh.setVisibility(View.GONE);
				rlSad.setVisibility(View.VISIBLE);
				rlWarm.setVisibility(View.GONE);
			}
		});
		rbWarm.setOnClickListener(new View.OnClickListener() {

			 
			public void onClick(View v) {
				rlFresh.setVisibility(View.GONE);
				rlSad.setVisibility(View.GONE);
				rlWarm.setVisibility(View.VISIBLE);
			}
		});
	}	
	
	private void setData(){
		gvAdapterFresh = new FreshAdapter(textfresh,imagesFresh, this);
		gvFresh.setAdapter(gvAdapterFresh);
		gvAdapterWarm = new WarmAdapter(textwarm,imagesWarm, this);
		gvWarm.setAdapter(gvAdapterWarm);
		gvAdapterSad = new SadAdapter(textsad,imagesSad, this);
		gvSad.setAdapter(gvAdapterSad);
		
	}
	
	private void setItemListener(){
		gvFresh.setOnItemClickListener(new OnItemClickListener(){

			 
			public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
				Log.i("MainActivity+++++++++++", "view:"+v);
				Log.i("MainActivity", "Position:" + position);
				Intent intent = new Intent(CoffeeMainActivity.this, ImageItemViewActivity.class);
				intent.putExtra("id", position);
				intent.putExtra("type", 1);
				startActivity(intent);
				
			}
			
		});
		
		gvWarm.setOnItemClickListener(new OnItemClickListener(){

			 
			public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
				Log.i("MainActivity+++++++++++", "view:"+v);
				Log.i("MainActivity", "Position:" + position);
				Intent intent = new Intent(CoffeeMainActivity.this, ImageItemViewActivity.class);
				intent.putExtra("id", position);
				intent.putExtra("warm", 2);
				startActivity(intent);
				
			}
			
		});
		
		gvSad.setOnItemClickListener(new OnItemClickListener(){

			 
			public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
				
				Log.i("MainActivity+++++++++++", "view:"+v);
				Log.i("MainActivity", "Position:" + position);
				Intent intent = new Intent(CoffeeMainActivity.this, ImageItemViewActivity.class);
				intent.putExtra("id", position);	
				intent.putExtra("sad", 3);
				startActivity(intent);
				
			}
			
		});
	
		
	}

}
